*Change working directory
cd "/Users/gehlbach/Dropbox/Projects/Handbook paper/Data"
clear matrix

/* CREATE PANEL DATA */

use terlist, clear
expand 11
sort ter
egen year = fill(4(1)14 4(1)14)
sort ter year
merge using privpanelDT
drop _m
sort ter year
save temp, replace

*Regiony Rossii (RR) 2000 for 1994 data, RR 2002 for 95-99 data, RR 2006 for 00-04 data
insheet using GRP.csv, clear
drop if ter == 1126 | ter == 1177
drop region
reshape long grp, i(ter) j(year)
replace year = year - 90
sort ter year
merge ter year using temp
drop _m
sort ter year
save temp, replace

/* merge regional data (replication data from APSR paper) */
use regional
sort ter year
merge ter year using temp
drop if _m == 1
drop _m

rename grp grpnom
gen grp = grpnom/cpi
gen lngrp = ln(grp)
replace distmo = distmo/1000
gen distmo_yr = distmo*year

*trends
foreach i of numlist 1 3/5 7 8 10/12 14 15 17/20 22 24/25 27/30 32/34 36/38 40/42 44/47 49 50 52/54 56/58 60 61 63/66 68/71 73 75 76 78/95 97/99 {
gen ter`i'trend = 0
replace ter`i'trend = year if ter == 1100 + `i'
}

 
/* PANEL REGRESSIONS */

*Two-way FEs
xi: reg privDT distmo_yr i.ter i.year, cluster(ter)
outreg2 using paneltable, nolabel bdec(3) bracket replace
preserve
xi i.ter i.year
global DV "privDT"
global SE2 "SE2privDT"
global GCOL "VprivDT1-VprivDT847"
global RHS "distmo_yr _I*"
quietly do FGLS
reg y_1 X_*, noc level(90)
outreg2 using paneltable, nolabel bdec(3) bracket
restore

*impute 1994 bureaucracy as 1995 bureaucracy
tsset ter year
replace lnburexecreg = f.lnburexecreg if year == 4
xi: reg privDT distmo_yr lngrp lnpop lnburexecreg i.ter i.year, robust
outreg2 using paneltable, nolabel bdec(3) bracket
preserve
xi i.ter i.year
global DV "privDT"
global SE2 "SE2privDT"
global GCOL "VprivDT1-VprivDT847"
global RHS "distmo_yr lngrp lnpop lnburexecreg _I*"
quietly do FGLS
reg y_1 X_*, noc level(90)
outreg2 using paneltable, nolabel bdec(3) bracket
restore


/* ROBUSTNESS */

xi: reg privDT distmo_yr i.ter i.year *trend, cluster(ter)
outreg2 using paneltable, nolabel bdec(3) bracket
xi: reg privDT distmo_yr lngrp lnpop lnburexecreg i.ter i.year *trend, cluster(ter)
outreg2 using paneltable, nolabel bdec(3) bracket

egen privDTmean = mean(privDT), by(ter)
gen privDTdif = abs(privDT - privDTmean)
gen outlier = 1 if privDTdif > .75 & privDTdif < .

xi: reg privDT distmo_yr i.ter i.year if outlier ~= 1, cluster(ter)
xi: reg privDT distmo_yr lngrp lnpop lnburexecreg i.ter i.year if outlier ~= 1, cluster(ter)
xi: reg privDT distmo_yr i.ter i.year *trend if outlier ~= 1, cluster(ter)
xi: reg privDT distmo_yr lngrp lnpop lnburexecreg i.ter i.year *trend if outlier ~= 1, cluster(ter)





